package com.qingyu.print.member.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.UUID;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qingyu.common.utils.PageUtils;
import com.qingyu.common.utils.Query;

import com.qingyu.print.member.dao.ImageDao;
import com.qingyu.print.member.entity.ImageEntity;
import com.qingyu.print.member.service.ImageService;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;


@Service("imageService")
public class ImageServiceImpl extends ServiceImpl<ImageDao, ImageEntity> implements ImageService {

    @Resource
    private  ImageDao imageDao;

    @Override
    public String save(MultipartFile file) throws IOException {

        InputStream inputStream = file.getInputStream();
        byte[] data = new byte[(int) file.getSize()];
        int i = inputStream.read(data);
        String id = UUID.randomUUID().toString();
        imageDao.insert(new ImageEntity(id,data));

        return id;
    }


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ImageEntity> page = this.page(
                new Query<ImageEntity>().getPage(params),
                new QueryWrapper<ImageEntity>()
        );

        return new PageUtils(page);
    }



}